﻿<phone:PhoneApplicationPage
    x:Class="SkiTracker.View.TrackPositionPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:maps="clr-namespace:Microsoft.Phone.Maps.Controls;assembly=Microsoft.Phone.Maps"
    xmlns:mapsext="clr-namespace:Microsoft.Phone.Maps.Toolkit;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:view="clr-namespace:SkiTracker.View"
    xmlns:util="clr-namespace:SkiTracker.Controls" xmlns:converter="clr-namespace:SkiTracker.Converter"
    xmlns:scada="clr-namespace:WPScadaControlsV2;assembly=WPScadaControlsV2"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d"
    shell:SystemTray.IsVisible="True">

    <phone:PhoneApplicationPage.Resources>
        <converter:BooleanToStringConverter x:Key="BooleanToStartStopConverter" True="Stop" False="Start" />
        <converter:InvertBooleanConverter x:Key="InvertBooleanConverter" />
    </phone:PhoneApplicationPage.Resources>

    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar Mode="Minimized" Opacity="1.0" IsMenuEnabled="True" IsVisible="True" >
            <shell:ApplicationBarIconButton Click="_1_Click" IconUri="/Assets/AppBar/Map.png" Text="Karte" />
            <shell:ApplicationBarIconButton Click="_2_Click" IconUri="/Assets/AppBar/Control.png" Text="Controls" IsEnabled="False" />
            <shell:ApplicationBarIconButton Click="_3_Click" IconUri="/Assets/AppBar/Stopwatch.png" Text="Speed" IsEnabled="False"/>
            <shell:ApplicationBarIconButton Click="_4_Click" IconUri="/Assets/AppBar/Tacho.png" Text="Tacho" IsEnabled="False"/>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel Grid.Row="0" Margin="12,17,0,28">
            <TextBlock Text="Ski-Tracker" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock Text="track" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0" >

            <!--ListBox-->
            <Grid Visibility="Visible" x:Name="CoordinatesListbox"
                  util:GridUtilities.RowDefinitions="Auto, *">
                <TextBlock Text="Koordinaten" FontSize="32"/>
                <ListBox ItemsSource="{Binding Coordinates}" Grid.Row="1">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock FontFamily="Consolas">
        						<Run Text="{Binding Latitude, StringFormat=##0.00000}"/>
        						<Run Text=" / " />
        						<Run Text="{Binding Longitude, StringFormat=##0.00000}"/>
        						<Run Text=" / " />
        						<Run Text="{Binding Altitude, StringFormat=##0.00000}"/>
                            </TextBlock>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </Grid>

            <!--Map-->
            <Grid x:Name="MapPanel" Visibility="Collapsed">

                <maps:Map x:Name="Map" TransformCenter="{Binding Transform, Mode=TwoWay }" Visibility="Collapsed"
                          Heading="{Binding Heading, Mode=TwoWay}" 
          		          CartographicMode="{Binding SelectedMode.CartographicMode, Mode=TwoWay}"
         		          Pitch="{Binding Pitch, Mode=TwoWay}"
         		          ZoomLevel="{Binding ZoomLevel, Mode=TwoWay}">

                    <mapsext:MapExtensions.Children>
                        <mapsext:MapChildControl GeoCoordinate="{Binding CurrentLocation}"
                                                 Visibility="{Binding CurrentLocation, Converter={StaticResource NullToVisibilityConverter}}">
                            <Path Data="M75.204,0.5 L150.953,249.667 L75.7265,189.171 L0.5,249.667" 
                                  Fill="{Binding AccentColor, ConverterParameter=80, Converter={StaticResource ColorToBrushConverter}}" 
                                  Stretch="Fill" Stroke="White" UseLayoutRounding="False" 
                                  Height="40" Width="40" RenderTransformOrigin="-60,-60" >
                                <Path.RenderTransform>
                                    <CompositeTransform TranslateX="-20" TranslateY="-20"/>
                                </Path.RenderTransform>
                            </Path>
                        </mapsext:MapChildControl>
                    </mapsext:MapExtensions.Children>

                </maps:Map>

                
                <view:MapControlUserControl Visibility="Collapsed" ShowHeadingSlider="{Binding IsHeadingAutomatic, Converter={StaticResource InvertBooleanConverter}}" x:Name="MapControl"/>


                <Grid Visibility="Collapsed" x:Name="TimerPanel"
                      Background="{Binding AccentColor, ConverterParameter=99, Converter={StaticResource ColorToBrushConverter}}"
                      Margin="22,0,52,22" VerticalAlignment="Bottom"
                      util:GridUtilities.RowDefinitions="30, 30, Auto"            
                      util:GridUtilities.ColumnDefinitions="Auto, *, Auto, *">
                    <TextBlock Text="Strecke:" Margin="10 0"/>
                    <TextBlock Text="{Binding DistanceInKm, StringFormat=\{0:0.00\} km}" Grid.Column="1" HorizontalAlignment="Right" Margin="10 0"/>
                    <TextBlock Text="Speed:" Grid.Column="2" Margin="10 0"/>
                    <TextBlock Text="{Binding SpeedInKmH, StringFormat=\{0:0.0\} km/h}" Grid.Column="3" HorizontalAlignment="Right" Margin="10 0"/>
                    <TextBlock Text="Zeit:" Grid.Row="1" Margin="10 0"/>
                    <TextBlock Text="{Binding ElapsedTime, StringFormat=HH:mm:ss}" Grid.Column="1" Grid.Row="1" HorizontalAlignment="Right" Margin="10 0"/>
                    <TextBlock Text="Höhe:" Grid.Row="1" Grid.Column="2" Margin="10 0"/>
                    <TextBlock Text="{Binding CurrentLocation.Altitude, StringFormat=\{0:0\} m}" Grid.Column="3" Grid.Row="1" HorizontalAlignment="Right" Margin="10 0"/>

                    <Button Content="{Binding IsTimerEnabled, Converter={StaticResource BooleanToStartStopConverter}}" Grid.Row="2" Grid.ColumnSpan="4" Command="{Binding StartStopTimerCommand}" />
                </Grid>



                <scada:RadialScale Visibility="Collapsed" x:Name="Speedometer"
                                   RangeThickness="10" RadialType="Circle" 
                                   Opacity="0.5"
                                   DefaultRangeColor="DimGray"
                                   DefaultTickColor="DimGray"
                                   UseRangeColorsForTicks="False"
                                   MinorTickStep="10" MajorTickStep="20" 
                                   Minimum="0" Maximum="80"
                                   MinAngle="-130" MaxAngle="130" Margin="30,0,30,0" >
                    <scada:RadialBarIndicator Value="{Binding Value, ElementName=SpeedMarker}" 
                                              BarThickness="20" 
                                              BarBrush="{StaticResource PhoneAccentBrush}" />

                    <scada:MarkerIndicator Value="{Binding MaxSpeedInKmH}">
                        <scada:MarkerIndicator.MarkerTemplate>
                            <DataTemplate>
                                <Rectangle Width="5" Height="20" Fill="#99FF0000"/>
                            </DataTemplate>
                        </scada:MarkerIndicator.MarkerTemplate>
                    </scada:MarkerIndicator>
                    
                    <scada:MarkerIndicator x:Name="SpeedMarker" Value="{Binding SpeedInKmH}">
                        <scada:MarkerIndicator.MarkerTemplate>
                            <DataTemplate>
                                <Rectangle Width="5" Height="20" Fill="#FFFF0000"/>
                            </DataTemplate>
                        </scada:MarkerIndicator.MarkerTemplate>
                    </scada:MarkerIndicator>

                </scada:RadialScale>

            </Grid>

        </Grid>

    </Grid>

</phone:PhoneApplicationPage>